PWD:=$(shell pwd)

OUTPUT_DIR:=$(PREFIX)
LIB_NAME:=liblog4z
MAIN_OBJ:=log4z.o

ifeq ($(LINKTYPE),shared)
CFLAGS := -fPIC
TARGET := $(LIB_NAME).so
else
TARGET := $(LIB_NAME).a
endif

ifeq ($(HOST),)
CROSS_COMPILE:=
else
CROSS_COMPILE:=$(HOST)-
endif

CC:=$(CROSS_COMPILE)g++
AR:=$(CROSS_COMPILE)ar

all: ${TARGET}

${LIB_NAME}.a:	$(MAIN_OBJ)
	$(AR) -r $(LIB_NAME).a $(MAIN_OBJ)
	
${LIB_NAME}.so:	$(MAIN_OBJ)
	$(CC) -fPIC -shared -o $(LIB_NAME).so $(MAIN_OBJ)

$(MAIN_OBJ):
	$(CC) $(CFLAGS) log4z.cpp -c -o $(MAIN_OBJ)
	
install:
	-mkdir -p $(OUTPUT_DIR)/lib
	-mkdir -p $(OUTPUT_DIR)/bin
	-mkdir -p $(OUTPUT_DIR)/include
	cp $(TARGET) $(OUTPUT_DIR)/lib
	cp log4z.h $(OUTPUT_DIR)/include/
	
.PHONY: clean
clean:
	@rm -rf *.o *.a *.so